package com.budwk.app.sqfw.services.common.impl;

import cn.hutool.core.bean.BeanUtil;
import com.budwk.app.sqfw.models.Sqfw_datamange_community;
import com.budwk.app.sqfw.models.Sqfw_online_template;
import com.budwk.app.sqfw.services.SqfwFormsummaryNewService;
import com.budwk.app.sqfw.services.datamange.DataMangeCommunityService;
import com.budwk.app.sqfw.services.common.SqfwOnlineTemplateService;
import com.budwk.app.sqfw.vo.SqfwOnlineTemplateVO;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.starter.common.page.Pagination;
import com.budwk.starter.database.service.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.nutz.aop.interceptor.ioc.TransAop;
import org.nutz.dao.Cnd;
import org.nutz.dao.Dao;
import org.nutz.dao.sql.Criteria;
import org.nutz.dao.util.cri.SqlExpressionGroup;
import org.nutz.ioc.aop.Aop;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;

import java.util.Date;

@Slf4j
@IocBean(args = {"refer:dao"})
public class SqfwOnlineTemplateServiceImpl extends BaseServiceImpl<Sqfw_online_template> implements SqfwOnlineTemplateService {
    public SqfwOnlineTemplateServiceImpl(Dao dao) {
        super(dao);
    }

    @Inject
    private SysUserService sysUserService;

    @Inject
    private SqfwFormsummaryNewService sqfwFormsummaryNewService;

    @Inject
    private DataMangeCommunityService sqfwFormsummaryOnlineService;

    @Override
    public Pagination list(SqfwOnlineTemplateVO bean) {
        long startTime = System.currentTimeMillis();
        // 构造查询条件
        Criteria criteria = buildQueryCond(bean);
        log.info("SqfwOnlineTemplateServiceImpl-list-SQL: {}", criteria.toString());
        Pagination pagination = listPage(1, 1000, criteria);
        log.info("SqfwOnlineTemplateServiceImpl-list-耗时: {}ms", System.currentTimeMillis() - startTime);
        return pagination;
    }

    /**
     * 新增数据
     *
     * @param bean
     * @return
     */
    @Override
    @Aop(TransAop.READ_COMMITTED)
    public void save(SqfwOnlineTemplateVO bean) {
        Sqfw_online_template sqfwOnlineTemplate = new Sqfw_online_template();
        BeanUtil.copyProperties(bean, sqfwOnlineTemplate);
        sqfwOnlineTemplate.setCreateDate(new Date());
        // this.insert(sqfwOnlineTemplate);
        Sqfw_datamange_community sqfwFormSummaryOnline = new Sqfw_datamange_community();
        BeanUtil.copyProperties(bean, sqfwFormSummaryOnline);
        //synSummaryData(sqfwOnlineTemplate, sqfwFormSummaryOnline);
        sqfwFormsummaryOnlineService.insert(sqfwFormSummaryOnline);
    }


    private Criteria buildQueryCond(SqfwOnlineTemplateVO bean) {
        Criteria cri = Cnd.cri();
        SqlExpressionGroup criSql = cri.where();

        return cri;
    }
}
